package exercise.jslide.jslide.view.dialog;

import exercise.jslide.jslide.model.text.TextStyle;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.stage.*;

public class TextStyleDialog {
    private Stage stage;
    private ComboBox<FontPosture> fontPostureComboBox;
    private ComboBox<FontWeight> fontWeightComboBox;
    private TextStyle textStyle;

    // 构造函数
    public TextStyleDialog(Stage parentStage) {
        stage = new Stage();
        stage.initOwner(parentStage); // 设置父窗口
        stage.initModality(Modality.WINDOW_MODAL); // 设置为模态对话框
        stage.getIcons().add(new Image(getClass().getResourceAsStream("/exercise/jslide/jslide/app/icons/LOGO.png")));
        stage.setTitle("选择字体样式");


        fontPostureComboBox = new ComboBox<>();
        fontPostureComboBox.getItems().addAll(FontPosture.values());
        fontPostureComboBox.setValue(FontPosture.REGULAR);

        fontWeightComboBox = new ComboBox<>();
        fontWeightComboBox.getItems().addAll(FontWeight.values());
        fontWeightComboBox.setValue(FontWeight.NORMAL);

        Button okButton = new Button("确定");
        okButton.setOnAction(e -> {
            textStyle = new TextStyle();
            textStyle.setFontStyle(fontPostureComboBox.getValue());
            textStyle.setFontWeight(fontWeightComboBox.getValue());
            stage.close();
        });

        VBox layout = new VBox(20);
        layout.setPadding(new Insets(20)); // 设置内边距为20
        layout.setAlignment(Pos.CENTER); // 设置对齐方式为居中
        layout.getChildren().addAll(
                new Label("字体样式:"), fontPostureComboBox,
                new Label("字体粗细:"), fontWeightComboBox,
                okButton
        );
        Scene scene = new Scene(layout, 300, 250);
        stage.setScene(scene);
    }

    // 显示对话框
    public void show() {
        stage.showAndWait();
    }

    // 隐藏对话框
    public void hide() {
        stage.close();
    }

    // 获取文本样式
    public TextStyle getTextStyle() {
        return textStyle;
    }
}